/*
 * Triangle2D.cpp
 *
 *  Created on: 31.1.2013
 *      Author: Travis
 */

#ifdef _WIN32 
#include <windows.h> 
#endif

#include "Triangle2D.h"

namespace DataTypes
{

Triangle2D::Triangle2D(glm::vec2 a, glm::vec2 b, glm::vec2 c)
{
	A = a;
	B = b;
	C = c;
}

Triangle2D::Triangle2D()
{
}

Triangle2D::~Triangle2D()
{
}

bool Triangle2D::pointInTriangle2D(glm::vec2 X)
{
	glm::mat2 inMatrix = glm::mat2(A.x - C.x, A.y - C.y, B.x - C.x, B.y - C.y);

	inMatrix = glm::inverseTranspose(inMatrix);

	glm::vec2 XC = glm::vec2(X.x - C.x, X.y - C.y);

	glm::vec2 result = inMatrix * XC;

	float gama = 1.0f - result.x - result.y;

	if (((0.0 <= result.x) && (result.x <= 1.0))
			&& ((0.0 <= result.y) && (result.y <= 1.0))
			&& ((0.0 <= gama) && (gama <= 1.0)))
	{
		return 1;
	}

	return 0;
}

//get
glm::vec2 Triangle2D::getA()
{
	return A;
}

glm::vec2 Triangle2D::getB()
{
	return B;
}

glm::vec2 Triangle2D::getC()
{
	return C;
}

//set
void Triangle2D::setA(glm::vec2 a)
{
	A = a;
}

void Triangle2D::setB(glm::vec2 b)
{
	B = b;
}

void Triangle2D::setC(glm::vec2 c)
{
	C = c;
}
}

